"""json提取工具类"""
import jsonpath
from utils.logger_utils import *


def jsonpath_exp(json_str,exp_key,index=0):
    try:
        exp_result = jsonpath.jsonpath(json_str, f"$..{exp_key}")[index]
        info(f"提取信息：key={exp_key},value={exp_result}")
    except Exception:
        exp_result = False
    if exp_result is False:
        error(f"提取失败！当前目标json={json_str},目标key={exp_key},请检查！")
    return exp_result